/*
 * Vector2.java
 * RVO2 Library Java
 *
 * Copyright 2008 University of North Carolina at Chapel Hill
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Please send all bug reports to <geom@cs.unc.edu>.
 *
 * The authors may be contacted via:
 *
 * Jur van den Berg, Stephen J. Guy, Jamie Snape, Ming C. Lin, Dinesh Manocha
 * Dept. of Computer Science
 * 201 S. Columbia St.
 * Frederick P. Brooks, Jr. Computer Science Bldg.
 * Chapel Hill, N.C. 27599-3175
 * United States of America
 *
 * <http://gamma.cs.unc.edu/RVO2/>
 */

package RVO;

/**
 * Defines a two-dimensional vector.
 */
public class Vector2 {
    public float x_;
    public float y_;

    /**
     * Constructs and initializes a two-dimensional vector from the
     * specified xy-coordinates.
     *
     * @param x The x-coordinate of the two-dimensional vector.
     * @param y The y-coordinate of the two-dimensional vector.
     */
    public Vector2(float x, float y) {
        x_ = x;
        y_ = y;
    }

    /**
     * Returns the string representation of this vector.
     *
     * @return The string representation of this vector.
     */
    @Override
    public String toString() {
        return "(" + x_ + "," + y_ + ")";
    }

    /**
     * Returns the x-coordinate of this two-dimensional vector.
     *
     * @return The x-coordinate of the two-dimensional vector.
     */
    public float x() {
        return x_;
    }

    /**
     * Returns the y-coordinate of this two-dimensional vector.
     *
     * @return The y-coordinate of the two-dimensional vector.
     */
    public float y() {
        return y_;
    }

    /**
     * Computes the dot product of the two specified
     * two-dimensional vectors.
     *
     * @param vector1 The first two-dimensional vector.
     * @param vector2 The second two-dimensional vector.
     * @return The dot product of the two specified two-dimensional vectors.
     */
    public static float multiply(Vector2 vector1, Vector2 vector2) {
        return vector1.x_ * vector2.x_ + vector1.y_ * vector2.y_;
    }

    /**
     * Computes the scalar multiplication of the specified
     * two-dimensional vector with the specified scalar value.
     *
     * @param scalar The scalar value.
     * @param vector The two-dimensional vector.
     * @return The scalar multiplication of the specified two-dimensional
     * vector with the specified scalar value.
     */
    public static Vector2 multiply(float scalar, Vector2 vector) {
        return multiply(vector, scalar);
    }

    /**
     * Computes the scalar multiplication of the specified
     * two-dimensional vector with the specified scalar value.
     *
     * @param vector The two-dimensional vector.
     * @param scalar The scalar value.
     * @return The scalar multiplication of the specified two-dimensional
     * vector with the specified scalar value.
     */
    public static Vector2 multiply(Vector2 vector, float scalar) {
        return new Vector2(vector.x_ * scalar, vector.y_ * scalar);
    }

    /**
     * Computes the scalar division of the specified
     * two-dimensional vector with the specified scalar value.
     *
     * @param vector The two-dimensional vector.
     * @param scalar The scalar value.
     * @return The scalar division of the specified two-dimensional vector
     * with the specified scalar value.
     */
    public static Vector2 divide(Vector2 vector, float scalar) {
        return new Vector2(vector.x_ / scalar, vector.y_ / scalar);
    }

    /**
     * Computes the vector sum of the two specified two-dimensional
     * vectors.
     *
     * @param vector1 The first two-dimensional vector.
     * @param vector2 The second two-dimensional vector.
     * @return The vector sum of the two specified two-dimensional vectors.
     */
    public static Vector2 add(Vector2 vector1, Vector2 vector2) {
        return new Vector2(vector1.x_ + vector2.x_, vector1.y_ + vector2.y_);
    }

    /**
     * Computes the vector difference of the two specified
     * two-dimensional vectors
     *
     * @param vector1 The first two-dimensional vector.
     * @param vector2 The second two-dimensional vector.
     * @return The vector difference of the two specified two-dimensional
     * vectors.
     */
    public static Vector2 subtract(Vector2 vector1, Vector2 vector2) {
        return new Vector2(vector1.x_ - vector2.x_, vector1.y_ - vector2.y_);
    }

    /**
     * Computes the negation of the specified two-dimensional
     * vector.
     *
     * @param vector The two-dimensional vector.
     * @return The negation of the specified two-dimensional vector.
     */
    public static Vector2 negate(Vector2 vector) {
        return new Vector2(-vector.x_, -vector.y_);
    }
}
